package com.xjlsoft.weather.service.impl;

import com.xjlsoft.weather.common.util.DataUtil;
import com.xjlsoft.weather.common.util.DateUtil;
import com.xjlsoft.weather.common.util.StringUtil;
import com.xjlsoft.weather.dto.ExportDto;
import com.xjlsoft.weather.dto.GroundDataListDto;
import com.xjlsoft.weather.dto.HighDataListDto;
import com.xjlsoft.weather.dto.WeatherDataQueryDto;
import com.xjlsoft.weather.entity.GroundData;
import com.xjlsoft.weather.entity.HighData;
import com.xjlsoft.weather.entity.HighDataExcelDto;
import com.xjlsoft.weather.entity.QueryLog;
import com.xjlsoft.weather.entity.ReponseConstant;
import com.xjlsoft.weather.entity.RequestApi;
import com.xjlsoft.weather.enums.ResultCodeEnum;
import com.xjlsoft.weather.enums.ResultStausEnum;
import com.xjlsoft.weather.mapper.GroundDataMapper;
import com.xjlsoft.weather.mapper.HighDataExcelDtoMapper;
import com.xjlsoft.weather.mapper.HighDataMapper;
import com.xjlsoft.weather.mapper.QueryLogMapper;
import com.xjlsoft.weather.mapper.ReponseConstantMapper;
import com.xjlsoft.weather.mapper.RequestApiMapper;
import com.xjlsoft.weather.service.HighDataExcelDtoService;
import com.xjlsoft.weather.service.HighDataService;
import com.xjlsoft.weather.util.WeatherDataUtil;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 高空-定时值数据表 按时间按站点 服务实现类
 * </p>
 *
 * @author zhangbanglong
 * @since 2020-07-22
 */
@Service
public class HighDataExcelDtoServiceImpl extends ServiceImpl<HighDataExcelDtoMapper, HighDataExcelDto> implements HighDataExcelDtoService {

	/**
	 * 日志
	 */
	private static final Logger logger = LoggerFactory.getLogger(GroundDataServiceImpl.class);

	@Value("${fileSaveDirPrefix}")
	private String fileSaveDirPrefix;// 文件存储根路径

	
	@Autowired
	private HighDataExcelDtoMapper  highDataExcelDtoMapper;

	

	
	@Override
	public List<HighDataExcelDto> getList(ExportDto exportDto) throws Exception {
		QueryWrapper<HighDataExcelDto> query = Wrappers.query();
		
    
		if(StringUtils.isNotBlank(exportDto.getDateStart())){
			Timestamp timestart=WeatherDataUtil.strToTimestamp(exportDto.getDateStart());
			query.ge("data_time", timestart);
		}
		if(StringUtils.isNotBlank(exportDto.getDateEnd())){
			Timestamp timeend=WeatherDataUtil.strToTimestamp(exportDto.getDateEnd());
			query.le("data_time", timeend);
		}
       
        List<HighDataExcelDto> list =highDataExcelDtoMapper.selectList(query);
        		//groundDataMaper.selectPage(page, query);
		return list;		// TODO Auto-generated method stub
	}




	@Override
	public List<Map<String, Object>> getListMap(ExportDto exportDto) throws Exception {
		QueryWrapper<HighDataExcelDto> query = Wrappers.query();
		query.select(exportDto.getSelectFilds());
	
		
		if(StringUtils.isNotBlank(exportDto.getDateStart())){
			Timestamp timestart=WeatherDataUtil.strToTimestamp(exportDto.getDateStart());
			query.ge("data_time", timestart);
		}
		if(StringUtils.isNotBlank(exportDto.getDateEnd())){
			Timestamp timeend=WeatherDataUtil.strToTimestamp(exportDto.getDateEnd());
			query.le("data_time", timeend);
		}
		 List<Map<String, Object>> map= highDataExcelDtoMapper.selectMaps(query);	
	     return map;
	}




	@Override
	public int getListMapCount(ExportDto exportDto) throws Exception {
		QueryWrapper<HighDataExcelDto> query = Wrappers.query();
		if(StringUtils.isNotBlank(exportDto.getDateStart())){
			Timestamp timestart=WeatherDataUtil.strToTimestamp(exportDto.getDateStart());
			query.ge("data_time", timestart);
		}
		if(StringUtils.isNotBlank(exportDto.getDateEnd())){
			Timestamp timeend=WeatherDataUtil.strToTimestamp(exportDto.getDateEnd());
			query.le("data_time", timeend);
		}
		int count=highDataExcelDtoMapper.selectCount(query);
		return count;
	}


	
	
}
